package algorithm.leetcode

class ReverseInt {

    fun reverse(a : Int) : Int{
        if(a < 10 || a > -10) return a

        var x = a
        var rev = 0
        val min = Int.MIN_VALUE / 10
        val max = Int.MAX_VALUE / 10
        while (x != 0){
            var pop = a % 10
            x /= 10
            if(rev > max || (rev == max && pop > 7)) return 0
            if(rev < min || (rev == min && pop < -8)) return 0
            rev = rev * 10 + pop
        }
        return rev
    }
}

fun main(args: Array<String>) {
    println(Int.MAX_VALUE)
    println(Int.MIN_VALUE)
//    println(ReverseInt().reverse(12345))
}